# 超级管理员操作界面

from PyQt5 import QtWidgets
from mysql import select_sql_all,updata_sql

class super_main(QtWidgets.QMainWindow):
    def __init__(self):
        super(super_main, self).__init__()


    def setupUI(self):
        self.setWindowTitle("超级管理员界面")
        self.setGeometry(100,100,400,400)
        self.Qbutton1()
        self.Qbutton2()




    def Qbutton1(self):
        pushbutton = QtWidgets.QPushButton(self)
        pushbutton.setText("查询被锁定卡")
        pushbutton.setGeometry(10,30,100,30)
        pushbutton.clicked.connect(self.Qbutton1_click)

    def Qbutton1_click(self):
        self.qtable2 = Qtable2()
        self.qtable2.setupUI()
        self.qtable2.show()
        self.hide()

    def Qbutton2(self):
        pushbutton = QtWidgets.QPushButton(self)
        pushbutton.setText("查询所有卡交易信息")
        pushbutton.setGeometry(120,30,150,30)
        pushbutton.clicked.connect(self.Qbutton2_click)

    def Qbutton2_click(self):
        self.qtable = Qtable1()
        self.qtable.setupUI()
        self.qtable.show()
        self.hide()



class Qtable1(QtWidgets.QMainWindow):
    def __init__(self):
        super(Qtable1, self).__init__()

    def setupUI(self):
        self.setWindowTitle("所有卡交易记录")
        self.setGeometry(200,100,660,660)
        self.Qtable()
        self.Qbutton2()

    def Qtable(self):
        self.qtable = QtWidgets.QTableWidget(self)
        self.qtable.setColumnCount(6)
        self.qtable.setGeometry(60, 60, 600, 600)
        # 禁止编辑
        self.qtable.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.qtable.verticalHeader().setVisible(False)
        self.qtable.setHorizontalHeaderLabels(["序号", "卡号", "时间", "金额", "类型", "对方卡号"])
        sql = "SELECT * FROM ATM.recode order by cdate desc"
        result = select_sql_all(sql)
        len_result = len(result)
        self.qtable.setRowCount(len_result)

        for i in range(len_result):
            self.qtable.setItem(i, 0, QtWidgets.QTableWidgetItem(str(i + 1)))
            self.qtable.setItem(i, 1, QtWidgets.QTableWidgetItem(str(result[i]['card'])))
            self.qtable.setItem(i, 2, QtWidgets.QTableWidgetItem(str(result[i]['cdate'])))
            self.qtable.setItem(i, 3, QtWidgets.QTableWidgetItem(str(result[i]['money'])))
            self.qtable.setItem(i, 4, QtWidgets.QTableWidgetItem(result[i]['status']))
            self.qtable.setItem(i, 5, QtWidgets.QTableWidgetItem(str(result[i]['card2'])))

    def Qbutton2(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("退回")
        qbutton.setGeometry(0,0,50,50)
        qbutton.clicked.connect(self.Qbutton2_click)

    def Qbutton2_click(self):
        self.close()
        self.b = super_main()
        self.b.setupUI()
        self.b.show()

class Qtable2(QtWidgets.QMainWindow):
    def __init__(self):
        super(Qtable2, self).__init__()

    def setupUI(self):
        self.setWindowTitle("被锁定的卡")
        self.setGeometry(200,100,660,660)
        self.Qlable()
        self.Qcombox()
        self.Qbutton()
        self.Qbutton2()

    def Qlable(self):
        qlable = QtWidgets.QLabel(self)
        qlable.setText("当前锁定的卡")
        qlable.setGeometry(10,10,100,30)

    def Qcombox(self):
        self.qcombox = QtWidgets.QComboBox(self)
        self.qcombox.setGeometry(120,10,100,30)
        sql = "SELECT card FROM ATM.User where status = 0"
        card = select_sql_all(sql)
        a = []
        for i in range(len(card)):
            a.append(str(card[i]['card']))
        self.qcombox.addItems(a)

    def Qbutton(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("解除锁定")
        qbutton.setGeometry(230,10,100,30)
        qbutton.clicked.connect(self.Qbutton_click)

    def Qbutton_click(self):
        # 返回选中选项的文本
        card = self.qcombox.currentText()
        sql = "UPDATE ATM.User SET ATM.User.status = 1 where card = '{0}'".format(int(card))
        updata_sql(sql)
        self.msg = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Information,"提示","修改完成")
        return self.msg.show()

    def Qbutton2(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("退回")
        qbutton.setGeometry(340,10,100,30)
        qbutton.clicked.connect(self.Qbutton2_click)

    def Qbutton2_click(self):
        self.close()
        self.b = super_main()
        self.b.setupUI()
        self.b.show()




